import reducer from '../reducers/calculator.js';
import { SET_NUMBER, CHANGE_METHOD } from '../actions/calculator.js';

// ctx是组件的实例对象
export default (ctx) => {

    // 把逻辑解构出来
    const {
        setNumber,
        changeMethod
    } = reducer(ctx.$data);

    return function (type, ...args) {
        switch (type) {
            case SET_NUMBER:
                ctx.result = setNumber(...args);
                break;
            case CHANGE_METHOD:
                ctx.result = changeMethod(...args);
                break;
            default:
                break;
        }
    }
}